// pages/shebei/shebei.js
var app = getApp();
Component({
	/**
	 * 组件的属性列表
	 */
	properties: {
		param:Object,
		isbuxian:{
			type:Number,
			value:''
		}
	},

	/**
	 * 组件的初始数据
	 */
	data: {
		data:[],
		activeId:0,
		activeText:'',
	},
	/**
	 * 组件的方法列表
	 */
	methods: {
		ShebeiClick(event){
			var sid = event.currentTarget.dataset.sid;
			var text = event.currentTarget.dataset.text;
			if(sid == 'not'){
				this.setData({
					activeId:0,
					activeText:''
				});
				this.triggerEvent("ShebeiChangeVal",{
					sid:0,
					text:''
				});
				return false;
			}else{
				this.setData({
					activeId:parseInt(sid),
					activeText:text
				});
				this.triggerEvent("ShebeiChangeVal",{
					sid:sid,
					text:text
				});
			}
			
		}
	},
	lifetimes: {
	    ready: function() {
			var shebei = app.globalData.shebei;
			var param = this.data.param;
			var text = param.activeText;
			if(!text && parseInt(param.activeId)>0){
				for(var i in shebei){
					for(var x in shebei[i].children){
						var item = shebei[i].children[x];
						if(parseInt(item.sid) == parseInt(param.activeId)){
							text = item.text;
						}
					}
				}
			}
			
			this.setData({
				activeId:param.activeId,
				activeText:text,
				data:shebei
			});
	    },
	    detached: function() {
	      // 在组件实例被从页面节点树移除时执行
	    },
	},
})
